home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Nov 90 / MacApp.Tech$ 11⁄16⁄90 / 2352-Streaming to the Res-Nov90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  3.1 KB  |  96 lines  |  [TEXT/GEOL]

  1. Item    1199452                         12-Nov-90        05:38PST
  2.  
  3. From:   POWERUP.ENG                     Power Up Software,PRT
  4.  
  5. To:     MACAPP.TECH$                    MacApp Technical
  6.  
  7. Sub:    Streaming to the Resource
  8.  
  9. Attn:   MacApp.Tech$
  10. SentBy: James Plamondon
  11. Date   11/9/90
  12. Subject    Streaming to the Resource F
  13. From   James Plamondon
  14. To Larry Rosenstein
  15. CC   MacApp.Tech$
  16.  
  17. Subject:   Streaming to the Resource Fork
  18. Dear Larry,
  19.  
  20. I have a problem with streaming with which I was hoping you might be able to
  21. help me.
  22.  
  23. My application displays pictures (among other things), and allows the user to
  24. copy and paste these pictures both between my app's documents and other
  25. applications.  Each picture is described by an instance of a class, TPict,
  26. which has roughly the following interface:
  27.  
  28. TPict = OBJECT(TStreamObject)
  29.    fResID:         INTEGER;    { negative if document has no file (not yet
  30. saved) }
  31.    fPicHandle:  PicHandle;   { must be non-nil if fResID is negative }
  32.  
  33.    { various methods, including ReadFrom() and WriteTo() }
  34.    …
  35. END;  { TPict }
  36.  
  37. It is assumed that each picture will be stored as a PICT resource in the
  38. resource fork of one of our application's documents.
  39.  
  40. The problem relates to the pasting of pictures into a document which has not
  41. yet been saved.  I can't save the pictures in the document's file's resource
  42. fork; there's no such file, so there's no such resource fork.
  43.  
  44. What I've tried doing is assigning unique negative ID's to each picture that
  45. is pasted into such a document.  The negative ID signals that the picture is
  46. described only by the data in fPicHandle, and not by a resource on disk.  When
  47. the document is saved, the following WriteTo() method is called for each
  48. picture:
  49.  
  50. PROCEDURE TPict.WriteTo(
  51.                        aStream:        TStream);
  52.                        OVERRIDE;
  53.    VAR
  54.        theResID:       INTEGER;
  55.  
  56.    BEGIN
  57.    theResID := abs(fResID);
  58.  
  59.    IF (Member(aStream, TFileStream)) &         { streaming to a file — kludge!
  60. }
  61.       (Get1Resource('PICT', theResID) = NIL)   { PICT isn't there already }
  62.    THEN
  63.        BEGIN
  64.        AddResource(                            { add the PICT to the file }
  65.            Handle(fPicHandle),
  66.            'PICT',
  67.            theResID,
  68.            '');
  69.        FailResError;
  70.  
  71.        fResID := theResID;     { if not saved before, it's saved now }
  72.        END;  { if }
  73.  
  74.    aStream.WriteInteger(fResID);
  75.    END; { WriteTo }
  76.  
  77. This code seems like it ought to work, but it doesn't (famous last words!).
  78. It fails every time with a adResFailed error (-194) after the call to
  79. AddResource().  I've set all of the appropriate flags to signal that my
  80. documents need to write to the resource fork, but — alas — it doesn't fly.
  81.  
  82. So, my questions for you, should you be so kind as to answer, are:
  83. •  Is my basic approach sound, or is there a better, easier way to accomplish
  84. this goal?
  85. •  Have you any idea how I could approach the problem of streaming a list of
  86. TPicts to the external scrap (given that only one PICT can be there at a
  87. time)?
  88. •  Can you see any reason why the AddResource() call should fail as it does?
  89.  
  90. With great appreciation for your assistance, I remain
  91.  
  92. Yours,
  93.  
  94. James Plamondon
  95.  
  96.